package com.tvsinfo.thread.synchroine;

/**
 * @Author ruyi.song
 * @Date 2020/04/29 10:28:43
 */
public class SynchroinedDemo {

    public static void main(String[] args) {
        System.out.println(System.currentTimeMillis());
    }

    void run(){
        User user=new User();
        Thread a=new Thread(() -> {
            user.getIDCard();
        });

        Thread b=new Thread(() -> {
            user.getUserName();
        });

        a.start();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        b.start();
    }


    public class User {

        public User() {
        }

        public synchronized void getIDCard() {
            try {
                System.out.println("getIDCard staring");
                Thread.sleep(10000);
                System.out.println("getIDCard result");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        public String getUserName() {
            try {
                System.out.println("getUserName staring");
                Thread.sleep(1000);
                System.out.println("getUserName result");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return null;
        }

    }

}
